package com.vv.edu.info.manager.service;

import com.vv.edu.info.manager.dao.TeacherDao;
import com.vv.edu.info.manager.domain.Teacher;

public class TeacherService {

    private final TeacherDao teacherDao = new TeacherDao();
    public boolean isExists(String id) {
        Teacher[] teachers = teacherDao.findAllTeacher();

        boolean exists = false;
        for (Teacher teacher : teachers) {
            if (teacher != null && teacher.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public Teacher[] findAllTeacher() {
        Teacher[] allTeacher = teacherDao.findAllTeacher();

        boolean flag = false;
        for (Teacher t : allTeacher) {
            if (t != null) {
                flag = true;
                break;
            }
        }
        if(flag) return allTeacher;
        else return null;
    }

    public void deleteTeacher(String id) {
        teacherDao.deleteTeacherById(id);
    }

    public void updataTeacher(String id, Teacher teacher) {
        teacherDao.updataTeacher(id, teacher);
    }
}
